"""
Case Type   : cm_uninstall
Case Name   : cm_uninstall显示帮助信息
Create At   : 2022/11/15
Owner       : opentestcase012
Description :
    1.cm_uninstall显示帮助信息
Expect      :
    1.执行成功，显示帮助信息正确且与实际一致
History     :
    2025/4/22 modified @ningyali 优化用例
"""
import os
import unittest

from testcase.utils.Common import Common
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro


class Tools(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'----{os.path.basename(__file__)} start----')
        self.pri_user = Node('PrimaryDbUser')
        self.common = Common()
        self.cm_tool_path = os.path.join(
            os.path.dirname(macro.DB_SCRIPT_PATH), 'tool', 'cm_tool')

    def test_standby(self):
        text = '----step1:cm_uninstall显示帮助信息 expect:成功----'
        self.log.info(text)
        help_cmd = f"cd {self.cm_tool_path};./cm_uninstall -?"
        help_res = self.common.get_sh_result(self.pri_user, help_cmd)
        help_msg = ['cm_uninstall is a utility to uninstall CM tool '
                    'to openGauss database cluster.',
                    'cm_uninstall -? | --help',
                    'cm_uninstall -X XMLFILE [-e envFile] '
                    '[--deleteData] [--deleteBinary]',
                    '-X                                 '
                    'Path of the XML configuration file',
                    '-e                                 Path of env file.',
                    'Default value "~/.bashrc".',
                    '--deleteData                       Specify to true '
                    'if you want to remove cmdatapath and GAUSSLOG/cm.',
                    '--deleteBinary                     Specify to true '
                    'if you want to remove CM binary file.',
                    '-?, --help                         '
                    'Show help information for this',
                    'utility, and exit the command line mode.']
        for content in help_msg:
            self.log.info(f'check [{content}] in help_res')
            self.assertIn(content, help_res, f'执行失败:{text}')

    def tearDown(self):
        self.log.info('----无需清理环境----')
        self.log.info(f'----{os.path.basename(__file__)} end----')
